@extends('admin.layout.main')
@section("content")
    {{--admin/customer--}}
    <form class="layui-form" action="" method="post">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>客户修改</legend>
        </fieldset>
        <div class="layui-form-item">
            <div class="layui-form-label">客户等级</div>
            <div id="rate-comm-1" value="1" name=customer_level class="rate-comm"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户状态：</label>
            <div class="layui-input-block">
                <select name="customer_type" lay-filter="source">
                    <option value="0" selected="">请选择一个客户状态</option>
                    <option value="意向客户" >意向客户</option>
                    <option value="已成交客户">已成交客户</option>
                    <option value="失败客户">失败客户</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">企业规模：</label>
            <div class="layui-input-block">
                <select name="company_size" lay-filter="source">
                    <option value="0" selected="">请选择规模</option>
                    <option value="10人以下" >10人以下</option>
                    <option value="10人-50人">10人-50人</option>
                    <option value="100人-500人">100人-500人</option>
                    <option value="500人-1000人">500人-1000人</option>
                    <option value="1000人以上">1000人以上</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">企业地址</label>
            <div id="city">
                <div class="layui-input-inline">
                    <select name="prov" class="prov"></select>
                </div>
                <div class="layui-input-inline">
                    <select name="city" class="city" disabled="disabled"></select>
                </div>
                <div class="layui-input-inline">
                    <select name="dist" class="dist" disabled="disabled"></select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">下次联系时间</label>
            <div class="layui-input-inline">
                <input type="text" name="next_time"  value="{{$customer->next_contact}}" id="date" lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系周期：</label>
            <div class="layui-input-block">
                <select name="contact_cycle" lay-filter="source">
                    <option value="0" selected="">请选择一个联系周期</option>
                    <option value="1" >1天</option>
                    <option value="2" >3天</option>
                    <option value="3">5天</option>
                    <option value="4">7天</option>
                    <option value="5">15天</option>
                    <option value="6">30天</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">分配用户</label>
                <div class="layui-input-inline">
                    <select name="user_id">
                        <option value="{{$customer->user_id}}">{{$customer->user_id}}</option>
                        <optgroup label="员工">
                            @foreach($users as $user)
                                <option value="{{$user->id}}">{{$user->name}}</option>
                            @endforeach
                        </optgroup>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">

                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script type="text/javascript">
        $(document).ready(function() {
                $("#city").citySelect({
                        prov: "陕西",
                        city: "西安",
                        dist: "雁塔区",
                        nodata: "none"
                });
        });
        layui.use(['element','form','laydate'], function() {
            var table = layui.table, form = layui.form,laydate = layui.laydate;

            form.on('submit(demo1)', function(data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                var customer_level="";
                if(document.getElementsByClassName('rater-star-result')!=null){
                    $str=document.getElementsByClassName('rater-star-result')[0].innerText;
                    customer_level=$str.substr(0,1);
                }
                //console.log(customer_level);
                //console.log('2')

                data.field.customer_level=customer_level;
                //console.log(data.field.customer_level);
                //window.location.href="/admin/customer";
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/admin/customer/update/{{$customer->id}}" ,//url
                    data:data.field,
                    success: function (result) {
                        alert("修改成功");
                        window.parent.location.reload()


                        //print_r(result);
                        //var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        //parent.layer.close(index); //再执行关闭

//                        if(result['statu']==0){
//                            layer.msg('请双击需要修改的地方，做出修改后再点击编辑 谢谢');
//                        }
//                        else{
//                            layer.msg('修改成功');
//                        }
                    },
                });
                return false;
            });


                //console.log($('.rater-star-result').innerText);
                //return true;
            });
            //日期
            laydate.render({
                elem: '#date'
            });
    </script>


@endsection
